package com.lxl.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Enumeration;

public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Get");
        System.out.println(request.getRemoteAddr());
//        Enumeration<String> enumer = request.getHeaderNames();
//        while(enumer.hasMoreElements()){
//            String key = enumer.nextElement();
//            System.out.println(key+"=="+request.getHeader(key));
//        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("post:");
        Enumeration<String> enumer = request.getHeaderNames();
        while(enumer.hasMoreElements()){
            String key = enumer.nextElement();
            System.out.println(key+"=="+request.getHeader(key));
        }

        BufferedReader reader = request.getReader();
        StringBuffer buffer = new StringBuffer();
        String line = " ";
        while ((line = reader.readLine()) != null){
            buffer.append(line);
        }
        System.out.println(buffer.toString());
    }
}
